<script type="text/html" template lay-done="layui.data.done(d);">

</script>
<script type="text/html" id="LAY-app-getGoodList-toolbar">
    <div class="layui-form coreshop-toolbar-search-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" for="name">商品名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="name" placeholder="请输入商品名称" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsGoods-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
            </div>
        </div>
    </div>
</script>
<div class="noDefaultToolbar">
    <table id="LAY-app-CoreCmsGoods-GoodsTable-TableBox" lay-filter="LAY-app-CoreCmsGoods-GoodsTable-TableBox"></table>
</div>

<script>
    var debug = layui.setter.debug;
    layui.data.done = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d); }
        layui.use(['index', 'table', 'coreHelper', 'table'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , table = layui.table;

                //重载form
                form.render();
                var searchwhere;
                //监听搜索
                form.on('submit(LAY-app-CoreCmsGoods-search)',
                    function (data) {
                        var field = data.field;
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsGoods-GoodsTable-TableBox', { where: field });
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsGoods-GoodsTable-TableBox',
                    url: layui.setter.apiUrl + 'Api/Tools/GetGoods',
                    method: 'POST',
                    toolbar:'#LAY-app-getGoodList-toolbar',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: '380px',//无面包屑127,搜索框189,1行62
                    page: true,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            { field: 'id', title: '商品ID', width: 80, sort: false },
                            { field: 'name', title: '商品名称', sort: false },
                            {
                                field: 'images', title: '图集', width: 100, sort: false,
                                templet: function (d) {
                                    if (d.images) {
                                        var arr = d.images.split(',');
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + arr[0] + '")><image style="max-width:28px;max-height:28px;" src="' + arr[0] + '" /></a>';
                                    } else {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                                    }
                                }
                            },
                            { field: 'stock', title: '库存', sort: false, width: 105 },
                            { width: 100, title: '操作', align: 'center', toolbar: '#goodsBar' }
                        ]
                    ]
                });
            });
    };
</script>
<script type="text/html" id="goodsBar">
    <a class="layui-btn layui-btn-xs" lay-event="selectGoods">选择</a>
</script>